import {getRecommendDetail} from '../../../api/recommedCourse';
Component({
  data:{
    title:"",
    courseId:0,
    courseDetail:{},
    selectCourseList:[]
  },
  methods:{
    onLoad(data:any){
      let {title,serialId} = data
      
    this.setData({
      title,
      serialId
    })
    this.getRecommedDetail()
    },
    // 获取推荐课程详情
    async getRecommedDetail(){
    const {code, data:res} = await getRecommendDetail({serialId:this.data.serialId})
if(code === 200){
this.setData({
  courseDetail:res
})
}    
    },
    seeRecommedDetail(e:any){
    const {courseserialid,courseserialname} = e.currentTarget.dataset
      wx.navigateTo({
        url:`/recommendCourse_package/pages/courseDetail/courseDetail?courseserialid=${courseserialid}&courseserialname=${courseserialname}`
      })
    },
    // 勾选课程购买
    checkHandle(e:any){
    let {index} = e.currentTarget.dataset
    const courseList = this.data.selectCourseList as any
    let selectCourseList = [] as any
    if(courseList.includes(index)){
      selectCourseList = this.data.selectCourseList.filter((val:number) =>val !== index)
      console.log(index,selectCourseList);
    }else{
    selectCourseList = this.data.selectCourseList.concat(index)   
    }
    
    this.setData({
      selectCourseList
    })
    },
    // 购买课程
    courseOrder(){
      console.log(this.data.courseDetail);
      const dataSER = this.data.courseDetail as any
      const token = getApp().getToken()
      if(token){
        wx.navigateTo({
          url:`/myCourse_package/pages/courseOrder/courseOrder?serialId=${dataSER.courseSerialId}`
        })
      }else{
        wx.navigateTo({
          url:"/pages/login/login"
        })
      }
    },
    // 分享课程页面
    onShareAppMessage(){
      const recommendName = this.data.title
      const courseSerialId = this.data.serialId
      return {
        title:"课程详情",
        path:`/recommendCourse_package/pages/CourseIntroduction/CourseIntroduction?title=${recommendName}&serialId=${courseSerialId}`
      }
    }
  }
})